<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
      <el-row>
        <el-form-item label="部件销售订单ID" prop="salepartorderid">
          <el-input
            v-model="queryParams.salepartorderid"
            placeholder="请输入部件销售订单ID"
            clearable
            @keyup.enter.native="handleQuery"
            oninput="value=value.replace(/[^\d.]/g,'')"
          />
        </el-form-item>
        <el-form-item label="部件ID" prop="partid">
          <el-input
            v-model="queryParams.partid"
            placeholder="请输入部件ID"
            clearable
            @keyup.enter.native="handleQuery"
            oninput="value=value.replace(/[^\d.]/g,'')"
          />
        </el-form-item>
        <el-form-item label="快递单号" prop="trackingnumber">
          <el-input
            v-model="queryParams.trackingnumber"
            placeholder="请输入快递单号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      </el-row>
      <el-row>
        <el-form-item label="客户ID" prop="customerid">
          <el-input
            v-model="queryParams.customerid"
            placeholder="请输入客户ID"
            clearable
            @keyup.enter.native="handleQuery"
            oninput="value=value.replace(/[^\d.]/g,'')"
          />
        </el-form-item>
        <el-form-item label="销售员ID" prop="salespersonid">
          <el-input
            v-model="queryParams.salespersonid"
            placeholder="请输入销售员ID"
            clearable
            @keyup.enter.native="handleQuery"
            oninput="value=value.replace(/[^\d.]/g,'')"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-row>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5"> -->
        <!-- <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['salepartorder:salepartorder:add']"
        >新增</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['salepartorder:salepartorder:edit']"
        >发货</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['salepartorder:salepartorder:remove']"
        >收货</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['salepartorder:salepartorder:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="salepartorderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column type="expand">
            <template slot-scope="props">
              <el-form label-position="left" inline class="demo-table-expand">
                <el-form-item label="物流ID">
                  <span>{{ props.row.logisticsid }}</span>
                </el-form-item>
                <el-form-item label="数量">
                  <span>{{ props.row.quantity }}</span>
                </el-form-item>
                <el-form-item label="联系电话">
                  <span>{{ props.row.contactnumber }}</span>
                </el-form-item>
                <el-form-item label="地址">
                  <span>{{ props.row.address }}</span>
                </el-form-item>
                <el-form-item label="创建时间">
                  <span>{{ props.row.createtime }}</span>
                </el-form-item>
                <el-form-item label="修改时间">
                  <span>{{ props.row.modifytime }}</span>
                </el-form-item>
              </el-form>
            </template>
          </el-table-column>
      <el-table-column label="部件销售订单ID" align="center" prop="salepartorderid" />
      <el-table-column label="部件ID" align="center" prop="partid" />
      <el-table-column label="客户ID" align="center" prop="customerid" />
      <el-table-column label="销售员ID" align="center" prop="salespersonid" />
<!--      <el-table-column label="物流ID" align="center" prop="logisticsid" /> -->
      <el-table-column label="物流单号" align="center" prop="trackingnumber" />
      <el-table-column label="物流状态" align="center" prop="status" >
      <template slot-scope="scope">
        <span v-if="scope.row.status === 5">未发货</span>
        <span v-if="scope.row.status === 6">运输中</span>
        <span v-if="scope.row.status === 7">已到达</span>
      </template>
      </el-table-column>
      <!-- <el-table-column label="数量" align="center" prop="quantity" /> -->
      <!-- <el-table-column label="联系电话" align="center" prop="contactnumber" /> -->
      <!-- <el-table-column label="地址" align="center" prop="address" />
      <el-table-column label="创建时间" align="center" prop="createtime" />
      <el-table-column label="修改时间" align="center" prop="modifytime" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
            <span v-if="scope.row.status === 5">
              <el-button
            size="medium"
            type="text"
            icon="el-icon-box"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['salepartorder:salepartorder:edit']"
          >发货</el-button>
          </span>
          </template>

         <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['salepartorder:salepartorder:remove']"
          >收货</el-button> -->
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改部件销售订单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="快递单号" prop="trackingnumber">
          <el-input v-model="form.trackingnumber" placeholder="请输入快递单号" />
        </el-form-item>
        <el-form-item label="快递公司" prop="couriercompany">
          <el-input v-model="form.couriercompany" placeholder="请输入快递公司" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSalepartorder, getSalepartorder, delSalepartorder, addSalepartorder, updateSalepartorder } from "@/api/salepartorder/salepartorder";

export default {
  name: "Salepartorder",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 部件销售订单表格数据
      salepartorderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        salepartorderid: null,
        partid: null,
        customerid: null,
        salespersonid: null,
        trackingnumber:null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        trackingnumber: [
          { required: true, message: "快递单号不能为空", trigger: "blur" }
        ],
        couriercompany: [
          { required: true, message: "快递公司不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询部件销售订单列表 */
    getList() {
      this.loading = true;
      listSalepartorder(this.queryParams).then(response => {
        this.salepartorderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        salepartorderid: null,
        partid: null,
        customerid: null,
        salespersonid: null,
        logisticsid: null,
        quantity: null,
        contactnumber: null,
        address: null,
        createtime: null,
        modifytime: null,
        deleted: null,
        trackingnumber:null,
        couriercompany:null,
        status:null

      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.salepartorderid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    // /** 新增按钮操作 */
    // handleAdd() {
    //   this.reset();
    //   this.open = true;
    //   this.title = "添加部件销售订单";
    // },
    /** 修改（发货）按钮操作 */
    handleUpdate(row) {
      this.reset();
      const salepartorderid = row.salepartorderid || this.ids
      getSalepartorder(salepartorderid).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "发货";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.salepartorderid != null) {
            updateSalepartorder(this.form).then(response => {
              this.$modal.msgSuccess("发货成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSalepartorder(this.form).then(response => {
              this.$modal.msgSuccess("出错");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    // /** 删除按钮操作 */
    // handleDelete(row) {
    //   const salepartorderids = row.salepartorderid || this.ids;
    //   this.$modal.confirm('是否确认删除部件销售订单编号为"' + salepartorderids + '"的数据项？').then(function() {
    //     return delSalepartorder(salepartorderids);
    //   }).then(() => {
    //     this.getList();
    //     this.$modal.msgSuccess("删除成功");
    //   }).catch(() => {});
    // },
    /** 导出按钮操作 */
    handleExport() {
      this.download('salepartorder/salepartorder/export', {
        ...this.queryParams
      }, `salepartorder_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style>
  .demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 90px;
    color: #515a6e;
  }
  .demo-table-expand .el-form-item {
    margin-left: 65px;
    margin-right: 0;
    margin-bottom: 0;
    width: 100%;
  }
</style>
